package com.gemme.gemme.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.gemme.gemme.R;

public class Product2SIngleView extends RelativeLayout {
    private Context context;
    public Product2SIngleView(Context context) {
        this(context,null);
    }

    public Product2SIngleView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public Product2SIngleView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        initView();
    }
    ImageView iv_picture;
    TextView tv_name;
    TextView tv_desc;
    TextView tv_price;
    RoundCheckBox checkbox;
    private void initView() {
        LayoutInflater.from(context).inflate(R.layout.product_2_single,this);
        iv_picture = findViewById(R.id.iv_picture);
        tv_name = findViewById(R.id.tv_name);
        tv_desc = findViewById(R.id.tv_desc);
        tv_price = findViewById(R.id.tv_price);
        checkbox = findViewById(R.id.checkbox);
    }

    public void checkIsVisible(boolean isVisible){
        if(isVisible){
            checkbox.setVisibility(VISIBLE);
        }else{
            checkbox.setVisibility(GONE);
        }
    }

    public RoundCheckBox getCheckbox() {
        return checkbox;
    }

    public void setData(TuijianBean.DataBean.RecordsBean recordsBean) {
        try {
//            iv_picture.setText(recordsBean.get);
            tv_name.setText(recordsBean.getBrandName());
            tv_desc.setText(recordsBean.getProductDesc());
            tv_price.setText(recordsBean.getAttributeSpecPrice());

            Glide.with(context).load(recordsBean.getAbbreviationPic()).into(iv_picture);
        }catch (Exception e){

        }
    }

    public Product2SIngleView setName(String name){
        tv_name.setText(name);
        return this;
    }

    public Product2SIngleView setDesc(String name){
        tv_desc.setText(name);
        return this;
    }
    public Product2SIngleView setPrice(String price){
        tv_price.setText(price);
        return this;
    }
    public Product2SIngleView setPicture(String imagePic){
        Glide.with(context).load(imagePic).into(iv_picture);
        return this;
    }

}
